package com.xxl.job.executor.mvc.controller;

import javax.annotation.Resource;

import com.xxl.job.executor.service.jobhandler.DataJobHandler;
import com.xxl.job.executor.service.jobhandler.SampleXxlJob;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//import com.xxl.job.executor.service.jobhandler.DeviceXxlJob;
//import com.xxl.job.executor.service.jobhandler.SampleXxlJob;

@Controller
@EnableAutoConfiguration
public class IndexController {

	@Resource
	//SampleXxlJob sampleXxlJob;
	DataJobHandler dataJobHandler;
	
	@Resource // 自动注入，spring boot会帮我们实例化一个对象
	private JdbcTemplate commonDao; // 一个通过JDBC连接数据库的工具类，可以通过这个工具类对数据库进行增删改查
 
    @RequestMapping("/")
    @ResponseBody
    String index() {
		String result="_1";
		try {
			//sampleXxlJob.kaoqingIpJobHandler();

			while(!result.endsWith("_0")) {
				result=dataJobHandler.dataJobHandler();

			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

//    		List<Map<String, Object>> deviceList = commonDao.queryForList("select * from kqsbgl where sfyx =1");
//			Map device = null;
//		 
//			for (int i = 0; i < deviceList.size(); i++) {
//				try {
//					LoginDevice treat = new LoginDevice();
//
//					device = deviceList.get(i);
//					deviceXxlJob.deviceJobHandler();
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//					continue;
//				}
//			}
        return "xxl job executor running.rowid:"+result;
    }

}